﻿open Clexer

//let p = Clexer.init @"..\..\test.c"
//let startTime = System.DateTime.Now

let ExecWithTimeMeasure proc = 
    let time' = System.DateTime.UtcNow
    let result = proc ()
    let time'' = System.DateTime.UtcNow
    result, time'' - time'

let runTest i test = 
    let (r,t) = ExecWithTimeMeasure test 
    printf "Test #%d\n Tokens count:%d\n Execution time(msec):%.3f\n" i r t.TotalMilliseconds 

runTest 1 (fun () ->
                ( let p = Clexer.init @"..\..\test.c"
                  let example = seq {
                    while not p.IsPastEndOfStream do
                            yield Clexer.initial p  
                    } in
                  (Seq.toList example).Length)) 
(*
let example = seq {
                    while not p.IsPastEndOfStream do
                            yield Clexer.initial p  
                    } in
let is_brace x =
    match x with
        | LBRACE _ -> true
        | RBRACE _ -> true
        | _ -> false
//let braces = Seq.filter is_brace example
let braces = example
let writer = new System.IO.StreamWriter(@"..\..\result.out")
//let res = Seq.toList example
//List.iter (fprintfn writer "%A ") res
//Seq.iter (printfn "%A ") braces
let len = (Seq.toList braces).Length
(*
Seq.iter (fun x ->
               len <- len + 1
               if (len mod 10 = 0) then
                   printfn "%d" len
               ()
         ) braces
*)
fprintfn writer "%d " len
//Seq.iter (fprintfn writer "%A ") braces
//Seq.iter (printfn "%A ") example
fprintfn writer "Working time: %s" ((System.DateTime.Now.Subtract startTime).ToString())
writer.Close()
//System.Console.ReadLine();
*)